<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/app.js"></script>
		<script src="js/jquery-3.5.1.min.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=CTItIOB2FdSFsDlRRmh6irRFhVgnqKqb"></script>
	</head>
	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript" charset="utf-8">
			
			var cid = localStorage.getItem("cid");
	
			mui.init({
			  pullRefresh : {
				container:"#refreshContainer",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
				down : {
				  style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
				  color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
				  height:'50px',//可选,默认50px.下拉刷新控件的高度,
				  range:'100px', //可选 默认100px,控件可下拉拖拽的范围
				  offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
				  auto: true,//可选,默认false.首次加载自动上拉刷新一次
				  callback :csh() //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				}
			  }
			});
			
			mui.plusReady(function() {
				var notise;//  /jz/notices	
				
				mui("#notes").on('tap', 'li', function(){
					var html = this.innerHTML;
					var t = html.split('<p class="mui-ellipsis">')[0].split('<div class="mui-media-body">')[1];
					var c = html.split('<p class="mui-ellipsis">')[1].split('</p>')[0];
					var sj = html.split('<p class="mui-ellipsis shijian">')[1].split('</p>')[0];
					mui.openWindow({
						url:'xq.html',
						id:'xq.html',
						extras:{
							title: t,
							content: c,
							shijian: sj
						}
					});
				});
				
				mui("#pyqlist").on('tap', 'li', function(){
					var html = this.innerHTML;
					var t = html.split('<p>发表于')[0].split('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')[1];
					var c = html.split('<div class="mui-card-content">')[1].split('</div>')[0];
					var sj = html.split('<p>发表于 ')[1].split('</p>')[0];
					var hi = html.split('<img src="')[1].split('"><div')[0];
					var vc = html.split('查看次数: ')[1].split('</div>')[0];
					var dynamicId = html.split('<input type="hidden" value="')[1].split('">')[0];
					console.log(dynamicId)

					mui.openWindow({
						url:'xqDt.html',
						id:'xqDt.html',
						extras:{
							title: t,
							content: c,
							shijian: sj,
							headImg: hi,
							vc: vc,
							dynamicId: dynamicId
						}
					});
				});
				
				
				sy();
				xy();
				getCid();
				var longitude, latitude; 
				plus.geolocation.getCurrentPosition(translatePoint, function(e) { 
					mui.toast("异常:" + e.message); 
				}); 

			});
			
			
			function csh(){
				sy();
				xy();
				getCid();
				
			}
			// 退出
			function tc(){
				localStorage.removeItem("account");
				localStorage.removeItem("password");
				mui.openWindow({
					url:'login.html',
					id:'login.html'
				});
				
				mui.ajax(ip+'/logout',{
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；   
				headers:{'Content-Type':'application/x-www-form-urlencoded'},
				success:function(data){
					mui.toast("退出成功！");
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					mui.toast("退出成功！");
					return 0;
				}
				});
			}
			function add0(m){return m<10?'0'+m:m }
			function formatTime(shijianchuo){
				
				console.log(shijianchuo)
				//shijianchuo是整数，否则要parseInt转换
				var time = new Date(shijianchuo);
				var y = time.getFullYear();
				var m = time.getMonth()+1;
				var d = time.getDate();
				var h = time.getHours();
				var mm = time.getMinutes();
				var s = time.getSeconds();
				return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
			}
			// 首页获取所有通知
			function sy(){
				mui.ajax(ip+'/user/notice/getAll',{
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；   
				headers:{'Content-Type':'application/x-www-form-urlencoded'},
				success:function(data){
					var nt = document.getElementById("notes");
					var html = "";
					console.log(data)
					for (i=0; i<data.length; i++) {
						html += '<li class="mui-table-view-cell mui-media">'+
						'<a href="javascript:;">'+
							'<img class="mui-media-object mui-pull-left" src="imgs/tubiao/144.png">'+
							'<div class="mui-media-body">'+
								data[i].title+
								'<p class="mui-ellipsis">'+data[i].content+'</p>'+
								'<p class="mui-ellipsis shijian">'+data[i].createTime+'</p>'+
							'</div>'+
						'</a>'+
					'</li>';
					}
					nt.innerHTML = html;
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					mui.toast("服务器错误！");
					return 0;
				}
				});
			}
			// 发布朋友圈
			function fb(){
				console.log("发布===");
				var userId = localStorage.getItem("userId");
				var content =  nt = document.getElementById("content").value;
				mui.ajax(ip+'/dynamic/doAdd?userId='+userId+"&content="+content,{
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；   
				headers:{'Content-Type':'application/x-www-form-urlencoded'},
				success:function(data){
				}
				});
				xy();
				xy();
				mui.toast("发布成功！");
			}
			
			// 所有动态
			function xy(){
				var a = localStorage.getItem("account");				
				mui.ajax(ip+'/dynamic/getAllByLimit',{
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				headers:{'Content-Type':'application/x-www-form-urlencoded'},
				success:function(data){
					
					console.log(data);
					var nt = document.getElementById("pyqlist");
					var html = '';
					for(var i = 0; i<data.rows.length; i++){
						var headImg = ip+"/file/"+data.rows[i].headImg+".png";
						
						html += '<li>'+
							'<div class="mui-card">'+
								'<div class="mui-card-header mui-card-media">'+
									'<img src="'+headImg+'" />'+
									'<div class="mui-media-body">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
										data.rows[i].name+
										'<p>发表于 '+data.rows[i].createTime+'</p>'+
									'</div>'+
								'</div>'+
								'<div class="mui-card-content">'+data.rows[i].content+'</div>'+
								'<div class="mui-card-footer">查看次数: '+data.rows[i].viewCount+'</div>'+
							'</div>'+
							'<input type="hidden" value="'+data.rows[i].id+'"/>'+
						'</li>';
					}
					html +='<div  style="text-align: center;">'+
								'<textarea rows="3" cols="20" placeholder="内容" id="content">'+
								'</textarea>'+
								'<button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" onclick="fb()">发布朋友圈</button>'+
							'</div>';
					nt.innerHTML = html;
					
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					mui.toast("服务器错误！");
					return 0;
				}
				});
			}
			// 获取用户信息
			function getCid(){
				var a = localStorage.getItem("account");
				mui.ajax(ip+'/user/getInfo?name='+a,{
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				headers:{'Content-Type':'application/x-www-form-urlencoded'},
				success:function(data){
					if(data!=null){
						cid = data.name;
						localStorage.setItem("cid", cid);
						localStorage.setItem("userId", data.id);
						console.log(data.id);
					}
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					mui.toast("服务器错误！");
					return 0;
				}
				});
			}

		</script>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">智能运动</h1>
		</header>

		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active" href="#sy">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="#qyd">
				<span class="mui-icon mui-icon mui-icon-flag"></span>
				<span class="mui-tab-label">去运动</span>
			</a>
			<a class="mui-tab-item" href="#byq">
				<span class="mui-icon mui-icon-weixin"></span>	
				<span class="mui-tab-label">步友圈</span>
			</a>
			<a class="mui-tab-item" href="#wd">
				<span class="mui-icon mui-icon mui-icon-person"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<div class="mui-content">
			<div id="sy" class="mui-control-content mui-active" onclick="sy();">
				<ul class="mui-table-view" id="notes">
					
				</ul>
			</div>

			<div id="qyd" class="mui-control-content">
			<ul class="mui-table-view" style="margin-top: 25px;">
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" style="color: #17ff2a;" href="start.html">
						开始打卡
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" style="color: #FF3B30;" href="end.html">
						结束打卡
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" style="color: #0000ff;" href="jl.html">
						打卡记录
					</a>
				</li>
			</ul>
			</div>
			
			<div id="byq" class="mui-control-content">
				<ul class="mui-table-view mui-table-view-chevron">
					<ul class="mui-table-view" id="pyqlist">	
					
					</ul>
				</ul>
			</div>

			<div id="wd" class="mui-control-content">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<a class="mui-navigate-right" href="wd.html">
							个人信息维护
						</a>
					</li>
					<li class="mui-table-view-cell">
						<a class="mui-navigate-right" href="sub.html">
							投诉反馈
						</a>
					</li>
					<li class="mui-table-view-cell">
						<a class="mui-navigate-right" href="rl.html">
							打卡日历
						</a>
					</li>
				</ul>
				<ul class="mui-table-view" style="margin-top: 25px;">
					<li class="mui-table-view-cell">
						<a style="text-align: center;color: #FF3B30;" onclick="tc();">
							退出登录
						</a>
					</li>
				</ul>
			</div>

		</div>

	</body>
</html>